package com.yanxin.credit.controller;

import com.yanxin.common.base.ResultBody;
import com.yanxin.common.utils.ResultUtils;
import com.yanxin.credit.dto.AmazonOrderDTO;
import com.yanxin.credit.service.IAmazonOrderService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/amazon-order")
@RequiredArgsConstructor
public class AmazonOrderController {

    private final IAmazonOrderService amazonOrderService;

    @PostMapping("/add")
    @ApiOperation("Add Amazon Order")
    public ResultBody addOrder(@RequestBody AmazonOrderDTO orderDTO) {
        return ResultUtils.success(amazonOrderService.insertOrder(orderDTO));
    }

    @DeleteMapping("/delete/{orderId}")
    @ApiOperation("Delete Amazon Order")
    public ResultBody deleteOrder(@PathVariable long orderId) {
        return ResultUtils.success(amazonOrderService.deleteOrder(orderId));
    }

    @GetMapping("/list")
    @ApiOperation("List Amazon Orders")
    public ResultBody listOrders(@RequestParam(required = false) Date orderDate,
            @RequestParam int pageNum,
            @RequestParam int pageSize) {
        return ResultUtils.success(amazonOrderService.listBySelective(orderDate, pageNum, pageSize));
    }
}